package client

import (
	"context"
	"github.com/golang/protobuf/ptypes/empty"
	"github.com/micro/go-micro/v2/client"
	"github.com/micro/go-micro/v2/client/grpc"
	"kop/framework/wrapper"
	"kop/pb"
	"kop/pb/service"
)

var StageService service.StageService

func init() {

	var c = grpc.NewClient(client.Wrap(wrapper.ClientLogWrapper))
	_ = c.Init()

	//s.Init(test.Flags()...)

	StageService = service.NewStageService("go.micro.srv.role", c)
}

func GetStage(ctx context.Context) *pb.Stage {

	var stage, err = StageService.GetStage(ctx, &empty.Empty{})
	if err != nil {
		panic(err)
	}

	return stage
}

func Next(stage *pb.Stage) *pb.Award {

	var resp, err = StageService.Next(context.Background(), stage)
	if err != nil {
		panic(err)
	}

	*stage = *resp.Stage
	return resp.Award
}
